import request from '@/utils/request'
// spu数据
// 获取列表
// /admin/product/{page}/{limit} 参数有第几页 显示第几条数据和三级联动id
export const getSpuList = function (page, limit, category3Id) {
    return request({
        url: `/admin/product/${page}/${limit}`,
        method: 'get',
        params: { category3Id }
    })
}

// 获取某个 SPU 的信息
export const getSpu = (spuId) => request({ url: `/admin/product/getSpuById/${spuId}`, method: 'get' })

// 获取品牌的信息
export const getTmList = () => request({ url: '/admin/product/baseTrademark/getTrademarkList', method: 'get' })

// 获取 SPU 图片
export const getSpuImg = (spuId) => request({ url: `/admin/product/spuImageList/${spuId}`, method: 'get' })

// 获取全部的销售属性
export const getBaseList = () => request({ url: '/admin/product/baseSaleAttrList', method: 'get' })


// 修改或者添加的保存的 api
export const postAddorupdatespu = (spu) => {
    // 判断有没有id值 有id值就是修改 没有就是添加
    if (spu.id) {
        return request({
            url: '/admin/product/updateSpuInfo',
            method: 'post',
            data: spu
        })
    } else {
        return request({
            url: '/admin/product/saveSpuInfo',
            method: 'post',
            data: spu
        })
    }
}

// 删除spu
export const deleteSpu = (spuId) => request({ url: `/admin/product/deleteSpu/${spuId}`, method: 'delete' })


/* 

/admin/product/spuImageList/{spuId} 获取图片列表
/admin/product/spuSaleAttrList/{spuId} 获取销售属性的数据
/admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id} 获取平台属性数据
*/

export const getImgList = (spuId) => request({ url: `/admin/product/spuImageList/${spuId}`, method: 'get' })
export const getSaleList = (spuId) => request({ url: `/admin/product/spuSaleAttrList/${spuId}`, method: 'get' })
export const getattrInfoList = (category1Id, category2Id, category3Id) => request({ url: `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`, method: 'get' })

// 保存添加 /admin/product/saveSkuInfo
export const addSave = (saveInfo) => {
    return request({
        url: '/admin/product/saveSkuInfo',
        method: 'post',
        data: saveInfo
    })
}

// 获取sku的列表 /admin/product/findBySpuId/{spuId}
export const getSkuList = (spuId) => request({ url: `/admin/product/findBySpuId/${spuId}`, method: 'get' })
